using System;
using System.Collections.Generic;
using System.Text;
using NUnit.Framework;
using QLKS.DataLayer.ManagerObjects;
using QLKS.DataLayer.BusinessObjects;
using QLKS.DataLayer.Base;

namespace QLKS.DataLayer.UnitTests
{
	[TestFixture]
    public partial class PhieuThuePhongTests : UNuitTestBase
    {
        protected IPhieuThuePhongManager manager;
		
		public PhieuThuePhongTests()
        {
            manager = managerFactory.GetPhieuThuePhongManager();
        }
		
		protected PhieuThuePhong CreateNewPhieuThuePhong()
		{
			PhieuThuePhong entity = new PhieuThuePhong();
			
			// You may need to maually enter this key if there is a constraint violation.
			entity.Id = "Test Tes";
			
			entity.NgayBatDau = DateTime.Now;
			entity.NgayKetThuc = DateTime.Now;
			entity.SoNgayThue = 87;
			entity.NgayLap = DateTime.Now;
			entity.NgayCapNhat = DateTime.Now;
			
			INhanVienManager nhanVien1Manager = managerFactory.GetNhanVienManager();
			entity.NhanVien1 = nhanVien1Manager.GetAll(1)[0];
			
			INhanVienManager nhanVien2Manager = managerFactory.GetNhanVienManager();
			entity.NhanVien2 = nhanVien2Manager.GetAll(1)[0];
			
			IPhongManager phongManager = managerFactory.GetPhongManager();
			entity.Phong = phongManager.GetAll(1)[0];
			
			return entity;
		}
		protected PhieuThuePhong GetFirstPhieuThuePhong()
        {
            IList<PhieuThuePhong> entityList = manager.GetAll(1);
            if (entityList.Count == 0)
                Assert.Fail("All tables must have at least one row for unit tests to succeed.");
            return entityList[0];
        }
		
		[Test]
        public void Create()
        {
            try
            {
				PhieuThuePhong entity = CreateNewPhieuThuePhong();
				
                object result = manager.Save(entity);

                Assert.IsNotNull(result);
            }
            catch(Exception ex)
            {
                Assert.Fail(ex.ToString());
            }
        }
        [Test]
        public void Read()
        {
            try
            {
                PhieuThuePhong entityA = CreateNewPhieuThuePhong();
				manager.Save(entityA);

                PhieuThuePhong entityB = manager.GetById(entityA.Id);

                Assert.AreEqual(entityA, entityB);
            }
            catch (Exception ex)
            {
                Assert.Fail(ex.ToString());
            }
        }
		[Test]
		public void Update()
        {
            try
            {
                PhieuThuePhong entityA = GetFirstPhieuThuePhong();
				
				entityA.NgayBatDau = DateTime.Now;
				
				manager.Update(entityA);

                PhieuThuePhong entityB = manager.GetById(entityA.Id);

                Assert.AreEqual(entityA.NgayBatDau, entityB.NgayBatDau);
            }
            catch (Exception ex)
            {
                Assert.Fail(ex.ToString());
            }
        }
        [Test]
        public void Delete()
        {
            try
            {
                PhieuThuePhong entity = GetFirstPhieuThuePhong();
				
                manager.Delete(entity);

                entity = manager.GetById(entity.Id);
                Assert.IsNull(entity);
            }
            catch (Exception ex)
            {
                Assert.Fail(ex.ToString());
            }
        }
	}
}

